#!/usr/bin/env bash

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

if [ $# -eq 0 ]
then
    nmcli dev wifi list
elif [ $# -eq 2 ]
then
    nmcli dev wifi connect "$1" password "$2"
elif [ $1 == "restart" ]
then
	# Uncomment if using OpenRc --- sudo rc-service NetworkManager restart
	# Uncomment if using SystemD --- sudo systemctl restart NetworkManager
	# Uncomment if using Sysvinit --- sudo /etc/init.d NetworkManager restart
else
    echo ""
    echo "con - a programm to connect to wifi networks using Network Manager."
    echo "Under GNU GPL v3 license"
    echo ""
    echo "notabug.org/TheFirstVicar/con"
    echo ""
    echo "Contact: kupriyanovkirill@gmail.com OR mephisto@openmail.cc"
    echo ""
    echo "Copyright © 2017, 2018 SINOPSYS"
    echo ""
    echo "---------- USAGE ----------"
    echo "con [NETWORK_NAME] [NETWORK_PASSWORD]"
    echo ""
    echo "If no arguments are provided then it prints available wifi networks."
    echo ""
    echo "Enter name and password. e.g. 'con my_wifi my_password'."
    echo ""
    echo "IF there is whitespace in the network name or password, quotate it like that:"
    echo "con \"my wifi\" \"my password\""
fi


# EOF

